<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.icss.th.common.util.SecureUtil"%>
<%
	// this is the array of [examID] in DB
	String encryptedExamID = (String)request.getAttribute("encryptedExamID");
	String encryptedTypeID = (String)request.getAttribute("encryptedTypeID");
	int[] neighbors = (int[])request.getAttribute("neighbors");
	// two params for pager
	int startpage = 0;
	int perpage = 10;
	try
	{
		int att_start = Integer.parseInt(request.getParameter("startpage"));
		int att_perpage = Integer.parseInt(request.getParameter("perpage"));
		if (att_start >= 0 && att_perpage > 0 && att_start * att_perpage <= 50 && neighbors[att_start * att_perpage] > 0)
		{
			startpage = att_start;
			perpage = att_perpage;
		}
	}
	catch (Exception e){}
	
	if (neighbors[0] == 0)
	{
		// similar list not ready 
%>	数据编制中...
<%
	}
	else
	{
		// a simple example to show similar questions
%>

	<ul>
<%
		for (int idx = startpage * perpage; idx < 50 && idx < (startpage + 1) * perpage; idx++)
		{
			if (neighbors[idx] > 0)
			{
				// Note: if you want to show exact texts of questions, call DB query here.
				//
				// A possible solution: 1. "select ... from ... where examID = ... or examID = ... or examID = ..."
				// 2. use two arrays: int[perpage] & String[perpage] to map examIDs and question texts
%>		<li><a href="/question?id=<%=SecureUtil.encryptPassword(String.valueOf(neighbors[idx]))%>>No.<%=idx + 1%></a></li>
<%
			}
		}
%>	</ul>
	<ul class="pager">
<%
		// show a pager for all 50 similar questions
		for (int page = 0; page < 50 && page < 49 / perpage + 1; page)
		{
			if (page != startpage)
			{
%>		<li><a href="/similarQ?id=<%=encryptedExamID%>&typeId=<%=encryptedTypeID%>&start=<%=page%>><%=page + 1%></a></li>
<%
			}
			else
			{
%>		<li><%=page + 1%></li>
<%
			}
		}
%>
	</ul>
<%	}
%>